14. 离散分布可视化参考答案

参考答案

def bar_heights(intervals, probabilities, total_probability):

    heights = []

    #概率区间归一化
    total_relative_prob = sum(probabilities)

    for i in range(0, len(probabilities)):
        bar_area = (probabilities[i] / total_relative_prob) * total_probability
        heights.append(bar_area / (intervals[i + 1] - intervals[i]))

    return heights